package com.android.baselibs.persenter;

import android.content.Context;


import com.android.baselibs.constract.RealtConstract;
import com.android.baselibs.model.BaseModel;
import com.android.baselibs.network.HttpType;
import com.lzy.okgo.model.HttpHeaders;

import java.util.Map;

/**
 * Created by zouqh on 2018/4/2.
 */

public class BasePersenter implements RealtConstract.Presenter, RealtConstract.OnLoadFirstDataListener {

    private RealtConstract.Model model;
    private RealtConstract.View view;
    private Context context;

    public BasePersenter(RealtConstract.View view, Context con) {
        this.view = view;
        model = new BaseModel();
        this.context = con;
    }


    @Override
    public void onSuccess(String bean, int urlCode) {
        hiddesDialog();
        view.returnData(bean, urlCode);
    }

    @Override
    public void onFailure(String str,int code, Exception e) {
        hiddesDialog();
        view.LoadError(str,code);
    }


    @Override
    public void loadData(Map<String, String> map, String msg, String url, int urlCode) {
//        if (null == customProgress || !customProgress.isShowing()) {
//            customProgress = CustomProgress.showNoTitle(context, msg, true, null);
//        }
        model.loadDataKey(url, map, this, urlCode);
    }

    @Override
    public void loadData(String json, String msg, String url, int urlCode) {
        model.loadDataJson(url, json, this, urlCode);
    }

    @Override
    public void loadDataHeader(Map<String, String> map, String msg, String url, int urlCode, HttpHeaders headers,HttpType httpType) {
        model.loadDataKeyHeader(url,map,this,urlCode,headers,httpType);
    }

    @Override
    public void loadDataGetHeader(Map<String, String> map, String msg, String url, int urlCode, HttpHeaders headers) {
        model.loadDataKeyGet(url,map,this,urlCode,headers);
    }

    private void hiddesDialog() {
//        if (null != customProgress && customProgress.isShowing()) {
//            customProgress.dismiss();
//        }
    }
}
